if lib and not lib.CreateDataSource then


function lib:CreateDataSource(sec_code, interval)
	interval = interval or INTERVAL_M1
	local data_source, error_desc
	if not self.ds then self.ds = {} end
	data_source = self.ds[(sec_code.code or sec_code) .. "_" .. interval]
	if not data_source then
		local instrument = self:GetInstrument(sec_code)
		if instrument then
			data_source, error_desc = CreateDataSource(instrument.class_code, instrument.code, interval)
			if data_source then
				data_source.instrument = instrument
				data_source.interval = interval
				data_source.Close__ = data_source.Close
				data_source.Close = function(self)
					lib.ds[self.instrument.code .. "_" .. self.interval] = nil
					message("Close ds " .. self.instrument.code .. "_" .. self.interval)
					return self:Close__()
				end
				self.ds[instrument.code .. "_" .. interval] = data_source
			end
		else
			error_desc = "GetInstrument Error " .. tostring(sec_code.code or sec_code)
		end
	end
	return data_source, error_desc
end


end -- of file
